package com.coffee.controller;

import com.coffee.entity.Coupon;
import com.coffee.entity.R;
import com.coffee.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 优惠劵控制器
 */
@RestController
@RequestMapping("/coupon")
public class CouponController {

    @Autowired
    private CouponService couponService;

    /**
     * 前台优惠卷展示
     * @return
     */
    @GetMapping("/list")
    public R list() {
        //查询优惠劵
        List<Coupon> couponList = couponService.list();
        return R.success(couponList);
    }

    @PostMapping("/delete")
    public R deleteById(String id) {
        //删除优惠劵
        couponService.deleteById(id);
        return R.success("删除成功");
    }

    /**
     * 后台优惠卷管理列表查询
     * @return
     */
    @GetMapping("/select")
    public R select(){
        List<Coupon> coupons = couponService.select();
        return R.success(coupons);
    }
    @PostMapping("/add")
    public R addCoupon(@RequestBody Coupon coupon){
        couponService.addCoupon(coupon);
        return R.success("新增成功");
    }
    @PostMapping("/update")
    public R update(@RequestBody Coupon coupon){
        couponService.updateCoupon(coupon);
        return R.success("修改成功");
    }
}
